<template>
	<view class="container">
		<mescroll-body ref="mescrollRef" :top="listTop" :down="downOption" :up="upOption" @init="mescrollInit" @down="downCallback"
		 @up="upCallback">
			<view class="notice-item" v-for="item in noticeList" :key="item.id">
				<text class="time">{{ item.created_at || item.time }}</text>
				<view class="content" @tap="navTo(item)">
					<text class="title">{{ item.title }}</text>
					<view class="img-wrapper" v-if="item.cover">
						<image class="pic" :src="item.cover" mode="aspectFit"></image>
					</view>
					<text class="introduce" v-if="item.description">
						{{ item.description }}
					</text>
					<view class="bot b-t">
						<text>查看详情</text>
						<i class="more-icon npIcon-you"></i>
					</view>
				</view>
			</view>
		</mescroll-body>

	</view>
</template>

<script>
	import MescrollMixin from "@/components/mescroll-uni/mescroll-mixins.js";
	export default {
		mixins: [MescrollMixin],
		data() {
			return {
				noticeList: [],
				downOption: {
					auto: true
				},
				upOption: {
					auto: false,
					page: {
						num: 0,
						size: 20
					},
					noMoreSize: 4,
					empty: {
						tip: '~ 空空如也 ~', // 提示
					}
				},
			}
		},
		onLoad() {

		},
		methods: {
			downCallback() {
				this.mescroll.resetUpScroll();
			},
			upCallback(page) {
				this.$http.get('api/default/notice', {
					page: page.num
				}).then((res) => {
					if (page.num == 1) {
						this.noticeList = [];
					}
					let hasNext = true;
					if (!("list" in res) || res.length < 20) {
						hasNext = false;
					}
					this.mescroll.endSuccess(res.length, hasNext);
					res.forEach((item) => {
						this.noticeList.push(item)
					})
				}).catch((error) => {
					this.mescroll.endErr();
				});
			},
			navTo(item) {
				uni.navigateTo({
					url: "/pages/article/detail?id=" + item.id
				});
			}
		}
	}
</script>

<style>
	page {
		background-color: #f8f8f8;
		padding-bottom: 30upx;
	}

	.notice-item {
		display: flex;
		flex-direction: column;
		align-items: center;
	}

	.time {
		display: flex;
		align-items: center;
		justify-content: center;
		height: 80upx;
		padding-top: 10upx;
		font-size: 26upx;
		color: #7d7d7d;
	}

	.content {
		width: 710upx;
		padding: 0 24upx;
		background-color: #fff;
		border-radius: 4upx;
	}

	.title {
		display: flex;
		align-items: center;
		line-height: 40rpx;
		min-height: 90upx;
		padding: 20rpx 0;
		font-size: 32upx;
		color: #303133;
	}

	.img-wrapper {
		width: 100%;
		height: 260upx;
		position: relative;
	}

	.pic {
		display: block;
		width: 100%;
		height: 100%;
		border-radius: 6upx;
	}

	.cover {
		display: flex;
		justify-content: center;
		align-items: center;
		position: absolute;
		left: 0;
		top: 0;
		width: 100%;
		height: 100%;
		background-color: rgba(0, 0, 0, 0.5);
		font-size: 36upx;
		color: #fff;
	}

	.introduce {
		display: inline-block;
		padding: 16upx 0;
		font-size: 28upx;
		color: #606266;
		line-height: 38upx;
	}

	.bot {
		display: flex;
		align-items: center;
		justify-content: space-between;
		height: 80upx;
		font-size: 24upx;
		color: #707070;
		position: relative;
	}

	.b-t:after {
		position: absolute;
		z-index: 3;
		left: 0;
		right: 0;
		height: 0;
		content: '';
		transform: scaleY(.5);
		border-bottom: 1px solid #E4E7ED;
	}

	.b-t:after {
		top: 0;
	}
</style>
